
//
//  LXEmoticonPageView.swift
//  weibo
//
//  Created by lixin on 16/4/25.
//  Copyright © 2016年 lixin. All rights reserved.
//

import UIKit

private let LXEmoticonPageViewCellId = "LXEmoticonPageViewCellId"

class LXEmoticonPageView: UICollectionView {
    
    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 视图设置
    private func setUI(){
    
        dataSource = self
        
        registerClass(LXEmoticonPageViewCell.self, forCellWithReuseIdentifier: LXEmoticonPageViewCellId)
        
        let layout = collectionViewLayout as! UICollectionViewFlowLayout
        
        layout.itemSize = CGSize(width: SCREENW, height: 216 - 37)
        
        //垂直和水平间距
        layout.minimumInteritemSpacing = 0
        
        layout.minimumLineSpacing = 0
        
        //滚动方向
        layout.scrollDirection = .Horizontal
    }

}

//MARK: - 数据源方法
extension LXEmoticonPageView: UICollectionViewDataSource{

    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        
        return LXEmoticonTools.sharedTools.allEmoticons.count
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return LXEmoticonTools.sharedTools.allEmoticons[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(LXEmoticonPageViewCellId, forIndexPath: indexPath) as! LXEmoticonPageViewCell
        
        cell.indexPath = indexPath
        
        cell.emoticons = LXEmoticonTools.sharedTools.allEmoticons[indexPath.section][indexPath.item]
        
        return cell
    }

}
